//
//  TongJiBaoBiaoItemTableViewCell.m
//  YaoHeAPP
//
//  Created by xyh on 16/6/23.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "TongJiBaoBiaoItemTableViewCell.h"
#import "QiuGouItemModel.h"
#import "StatisticsModel.h"
#import "TongYong.h"
#import "NSString+formatWithFloat.h"
#import "UILabel+StringFrame.h"
@interface TongJiBaoBiaoItemTableViewCell () {
    NSInteger _kuan;
    NSInteger _jiange;
}
@property (nonatomic, strong) UILabel *oneLabel;
@property (nonatomic, strong) UILabel *twoLabel;
@property (nonatomic, strong) UILabel *threeLabel;
@property (nonatomic, strong) UILabel *fourLabel;
@property (nonatomic, strong) UILabel *fiveLabel;
@property (nonatomic, strong) UIImageView *jiantouImage;

@end

@implementation TongJiBaoBiaoItemTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        //间隔
        _kuan=70;
        _jiange=(SCREEN_WIDTH-(_kuan*5))/6;
        
        _oneLabel = [[UILabel alloc] initWithFrame:CGRectMake(_jiange+(_jiange+_kuan)*0, 0, _kuan, 30)];
        _oneLabel.font = Font(10);
        //自动折行设置
        _oneLabel.lineBreakMode = NSLineBreakByWordWrapping;
//        UILineBreakModeWordWrap;
        _oneLabel.numberOfLines = 0;
        _oneLabel.textAlignment = NSTextAlignmentCenter;
        _oneLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:_oneLabel];
       
        
        _twoLabel = [[UILabel alloc] initWithFrame:CGRectMake(_jiange+(_jiange+_kuan)*1, 5, _kuan, 20)];
        _twoLabel.font = Font(10);
        _twoLabel.textAlignment = NSTextAlignmentCenter;
        _twoLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:_twoLabel];
        
        _threeLabel = [[UILabel alloc] initWithFrame:CGRectMake(_jiange+(_jiange+_kuan)*2, 5, _kuan, 20)];
        _threeLabel.font = Font(10);
        _threeLabel.textAlignment = NSTextAlignmentCenter;
        _threeLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:_threeLabel];

        _fourLabel = [[UILabel alloc] initWithFrame:CGRectMake(_jiange+(_jiange+_kuan)*3, 5, _kuan, 20)];
        _fourLabel.font = Font(10);
        _fourLabel.textAlignment = NSTextAlignmentCenter;
        _fourLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:_fourLabel];

        _fiveLabel = [[UILabel alloc] initWithFrame:CGRectMake(_jiange+(_jiange+_kuan)*4, 5, _kuan, 20)];
        _fiveLabel.font = Font(10);
        _fiveLabel.textAlignment = NSTextAlignmentCenter;
        _fiveLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:_fiveLabel];

        
        //右边的图片
        _jiantouImage = [[UIImageView alloc]initWithFrame:CGRectMake(_fiveLabel.right,3, 10, 20)];
        _jiantouImage.image = [UIImage imageNamed:@"bottomimage"];
        _jiantouImage.hidden = YES;
        [self.contentView addSubview:_jiantouImage];
        
        
        UIView *fenjiexian = [[UIView alloc] initWithFrame:CGRectMake(0, 29, SCREEN_WIDTH, 0.5)];
        fenjiexian.backgroundColor = RGBCOLOR(230, 232, 241);
        [self.contentView addSubview:fenjiexian];
    }
    return self;
}

- (void)setQiuGouItemModel:(QiuGouItemModel *)qiuGouItemModel {
    _qiuGouItemModel = qiuGouItemModel;
   
    _oneLabel.text = qiuGouItemModel.USER_NAME;
    _twoLabel.text = [NSString stringWithFormat:@"%@/%@", qiuGouItemModel.PURCHASE_NUM, qiuGouItemModel.PUSH_NUM];
    _threeLabel.text =  qiuGouItemModel.QUOTE_NUM;
    _fourLabel.text =  qiuGouItemModel.SUCCESS_NUM;
    
    //保留两位小数
    NSDecimalNumber *SUCCESS_RATE = [[NSDecimalNumber alloc] initWithString:qiuGouItemModel.SUCCESS_RATE];//个数
    self.fiveLabel.text = [NSString stringWithFormat:@"%@%%", [NSString notRounding:SUCCESS_RATE afterPoint:2]];
    
}

- (void)setStatisticsModel:(StatisticsModel *)statisticsModel {
    _statisticsModel = statisticsModel;
    
    if ([TongYong isBlankObjectAndStr:statisticsModel.WEEK_INDEX]) {
        self.oneLabel.text =[NSString stringWithFormat:@"%@",statisticsModel.DATE_TIME];
    }else{
        _oneLabel.font = Font(9);
        self.oneLabel.text =[NSString stringWithFormat:@"第%@周 %@",statisticsModel.WEEK_INDEX,statisticsModel.DATE_TIME];
    }
    self.twoLabel.text = [NSString stringWithFormat:@"%d", statisticsModel.PURCHASE_NUM];
    self.threeLabel.text = statisticsModel.LOCK_NUM;
    self.fourLabel.text = [NSString stringWithFormat:@"%d", statisticsModel.SUCCESS_NUM];
    
    //保留两位小数
    NSDecimalNumber *SUCCESS_RATE = [[NSDecimalNumber alloc] initWithString:statisticsModel.SUCCESS_RATE];//个数
    self.fiveLabel.text = [NSString stringWithFormat:@"%@%%", [NSString notRounding:SUCCESS_RATE afterPoint:2]];
    
    //第五个居中
    CGSize tempSize = [self.fiveLabel boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 15)];
    float Fiv_y=(_jiange+(_jiange+_kuan)*4)+(SCREEN_WIDTH-(_jiange+(_jiange+_kuan)*4))/2-(tempSize.width/2);
    self.fiveLabel.frame = CGRectMake(Fiv_y, 5, tempSize.width, 15);
    self.jiantouImage.frame = CGRectMake(_fiveLabel.right,3, 10, 20);
    
    float INCREASE_RATE =statisticsModel.INCREASE_RATE.floatValue;
    //判断成交率箭头
    if (INCREASE_RATE < 0){
        _jiantouImage.hidden=NO;
        _jiantouImage.image=[UIImage imageNamed:@"bottomimage"];
    }else if (INCREASE_RATE==0){
        _jiantouImage.hidden=YES;
    }else{
        _jiantouImage.hidden=NO;
        _jiantouImage.image=[UIImage imageNamed:@"topimage"];
    }
}
@end
